package logic

import (
	"context"
	"src/internal/svc"
	"src/models/mysql"
	"src/src"
	"src/srcclient"
	"strconv"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderListLogic {
	return &OrderListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderListLogic) OrderList(in *src.OrderListRequest) (*src.OrderListResponse, error) {
	// todo: add your logic here and delete this line
	var list []mysql.Order
	mysql.DB.Debug().Model(&list).Find(&list)

	var slice []*srcclient.OrderListStruct

	for _, good := range list {
		lists := srcclient.OrderListStruct{
			Total:     int64(good.Total),
			NumberIng: good.NumberIng,
			Title:     good.Title,
			Stock:     strconv.Itoa(good.Stock),
			Status:    good.Status,
		}
		slice = append(slice, &lists)
	}
	return &src.OrderListResponse{OrderList: slice}, nil
}
